
#include <swegl/Data/Cube.h>
#include <swegl/projection/Vec2f.h>
#include <swegl/projection/Vec3f.h>
#include <swegl/Data/Texture.h>

namespace swegl
{

	Cube::Cube(float size, Texture *t)
	{
		Mesh::Mesh();

		this->m_texture = t;
		this->m_vertexbuffer.reserve(8);
		m_vertexbuffer.emplace_back(Vec3f(-size/2.0f, -size/2.0f, -size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f( size/2.0f, -size/2.0f, -size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f(-size/2.0f,  size/2.0f, -size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f( size/2.0f,  size/2.0f, -size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f(-size/2.0f, -size/2.0f,  size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f( size/2.0f, -size/2.0f,  size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f(-size/2.0f,  size/2.0f,  size/2.0f));
		m_vertexbuffer.emplace_back(Vec3f( size/2.0f,  size/2.0f,  size/2.0f));
	
		Vec2f t0, t1, t2, t3;
		t0.x= 0.01f;                         t0.y=-0.01f+t->m_mipmaps[0].m_height;
		t1.x=-0.01f+t->m_mipmaps[0].m_width; t1.y=-0.01f+t->m_mipmaps[0].m_height;
		t2.x= 0.01f;                         t2.y= 0.01f;
		t3.x=-0.01f+t->m_mipmaps[0].m_width; t3.y= 0.01f;

		std::vector<Vec2f> tb1;
		tb1.reserve(18);
		
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t1)); tb1.emplace_back(Vec2f(t3));
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t3)); tb1.emplace_back(Vec2f(t2)); 
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t1)); tb1.emplace_back(Vec2f(t3)); 
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t3)); tb1.emplace_back(Vec2f(t2)); 
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t1)); tb1.emplace_back(Vec2f(t3)); 
		tb1.emplace_back(Vec2f(t0)); tb1.emplace_back(Vec2f(t3)); tb1.emplace_back(Vec2f(t2)); 

		std::vector<unsigned int> ib1;
		ib1.reserve(8);
		ib1.push_back(0);
		ib1.push_back(1);
		ib1.push_back(3);
		ib1.push_back(2);
		ib1.push_back(6);
		ib1.push_back(4);
		ib1.push_back(5);
		ib1.push_back(1);
		AddFan(std::move<>(ib1), std::vector<Vec2f>(tb1));
	//*
		std::vector<unsigned int> ib2;
		ib2.reserve(8);
		ib2.push_back(7);
		ib2.push_back(6);
		ib2.push_back(2);
		ib2.push_back(3);
		ib2.push_back(1);
		ib2.push_back(5);
		ib2.push_back(4);
		ib2.push_back(6);
		AddFan(std::move<>(ib2), std::move<>(tb1));
	/**/
	}

}
